// (".[\u4E00-\u9FA5]+)|([\u4E00-\u9FA5]+.");
// [\x{4e00}-\x{9fa5}]
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import Formatter from './formatter'

import Element from 'element-ui'
import '../element-variables.scss'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'

import zhCN from './zh-cn/index'
import enUS from './en-US/index'

import localeService from '../service/locale'

Vue.use(VueI18n)

let locale = localeService.validateLocale(localStorage.getItem('locale'))

const formatter = new Formatter({ locale })

const i18n = new VueI18n({
  locale,
  formatter,
  messages: {
    'en-US': {
      message: enUS,
      ...enLocale
    },
    'zh-CN': {
      message: zhCN,
      ...zhLocale
    }
  }
})

Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})

export default i18n
